<template>
  <div>
    <el-form ref="dataForm" v-model="query" class="form" :rules="rules">
      <el-form-item prop="ck_007_sys_setting_1_1">
        <el-checkbox v-model="query.ck_007_sys_setting_1_1">呼叫下单时处理机构，仅显示门市级别</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_1_2">
        <el-checkbox v-model="query.ck_007_sys_setting_1_2">查询处理人时包含上级机构人员</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_1_3">
        <el-checkbox v-model="query.ck_007_sys_setting_1_3">呼叫下单时客户备注自动带入订单备注</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_2_28">
        <el-checkbox v-model="query.ck_007_sys_setting_2_28">话务录制保单默认审核</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_1_4">
        <el-checkbox v-model="query.ck_007_sys_setting_1_4">下单时处理人默认为主管</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_1_9">
        <el-checkbox v-model="query.ck_007_sys_setting_1_9">下单时处理人默认为上次处理人</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_1_16">
        <el-checkbox v-model="query.ck_007_sys_setting_1_16">下单时自动默认上次订气商品</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_1_11">
        <el-checkbox v-model="query.ck_007_sys_setting_1_11">下单界面隐藏保险相关项</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_3_15">
        <el-checkbox v-model="query.ck_007_sys_setting_3_15">下单界面隐藏省市区</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp4_9">
        <el-checkbox v-model="query.ck_007_sys_setting_sp4_9">下单商品关联客户气瓶库存</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_1_29">
        <el-checkbox v-model="query.ck_007_sys_setting_1_29">门店下单默认都是自提</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_2_27">
        <el-checkbox v-model="query.ck_007_sys_setting_2_27">所有订单均需回执</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp6_28">
        <el-checkbox v-model="query.ck_007_sys_setting_sp6_28">现金订单回执时，需要用银行支付再次付款</el-checkbox>
      </el-form-item>
      <el-form-item v-if="userInfo.userName === '007'" prop="ck_007_sys_setting_3_2">
        <el-checkbox v-model="query.ck_007_sys_setting_3_2">话务下单快捷查询允许本地二次检索</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp6_22">
        <el-checkbox v-model="query.ck_007_sys_setting_sp6_22">退货时，选择退货类型</el-checkbox>
      </el-form-item>
      <el-form-item prop="monthlyDayNum">
        月结客户超过  <el-input-number v-model="query.monthlyDayNum" controls-position="right" :min="0" /> 天未结清，下单时提示
      </el-form-item>
      <el-divider />
      <el-form-item prop="ck_007_sys_setting_1_6">
        <el-checkbox v-model="query.ck_007_sys_setting_1_6">微信商城一键订气不显示单价</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_1_10">
        <el-checkbox v-model="query.ck_007_sys_setting_1_10">微信商城评价后奖励抽奖机会</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_1_17">
        <el-checkbox v-model="query.ck_007_sys_setting_1_17">微信商城下单计算上楼费</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_3_9">
        <el-checkbox v-model="query.ck_007_sys_setting_3_9">微信人工审核兑换订单</el-checkbox>
      </el-form-item>
      <el-form-item prop="buyMax" label="微信同一商品下单数量限制:">
        <el-input-number v-model="query.buyMax" size="mini" controls-position="right" :min="1" :max="999" :precision="0" />
      </el-form-item>
      <el-form-item prop="exchangeBuyMax" label="兑换同一商品下单数量限制:">
        <el-input-number v-model="query.exchangeBuyMax" size="mini" controls-position="right" :min="1" :max="999" :precision="0" />
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_1_27">
        <el-checkbox v-model="query.ck_007_sys_setting_1_27">微信客户允许查看其他下单渠道的订单</el-checkbox>
      </el-form-item>
      <el-form-item prop="le" label="呼叫下单所属机构默认展开:">
        <el-input-number v-model="query.le" size="mini" controls-position="right" :min="1" :max="7" :precision="0" />
      </el-form-item>
      <el-form-item prop="orderAppointCount" label="允许修改预约时间次数:">
        <el-input-number v-model="query.orderAppointCount" size="mini" controls-position="right" :min="1" :max="99" :precision="0" />
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_1_23">
        <el-checkbox v-model="query.ck_007_sys_setting_1_23">门店下单(包含代客下单)所有商品使用机构挂牌价</el-checkbox>
      </el-form-item>

      <p class="title">市价</p>
      <el-form-item prop="ck_007_sys_setting_sp5_16">
        <el-checkbox v-model="query.ck_007_sys_setting_sp5_16">话务下单允许修改市价</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp5_17">
        <el-checkbox v-model="query.ck_007_sys_setting_sp5_17">门店下单允许修改市价</el-checkbox>
      </el-form-item>
      <p class="title">优惠</p>
      <el-form-item prop="ck_007_sys_setting_sp5_24">
        <el-checkbox v-model="query.ck_007_sys_setting_sp5_24">话务下单允许修改优惠金额</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp5_25">
        <el-checkbox v-model="query.ck_007_sys_setting_sp5_25">门店下单允许修改优惠金额</el-checkbox>
      </el-form-item>
      <p class="title">远距离配送费</p>
      <el-form-item prop="ck_007_sys_setting_sp5_18">
        <el-checkbox v-model="query.ck_007_sys_setting_sp5_18">话务下单允许修改远距离配送费</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp5_19">
        <el-checkbox v-model="query.ck_007_sys_setting_sp5_19">门店下单允许修改远距离配送费</el-checkbox>
      </el-form-item>
      <p class="title">上楼费</p>
      <el-form-item prop="ck_007_sys_setting_sp5_20">
        <el-checkbox v-model="query.ck_007_sys_setting_sp5_20">话务下单允许修改上楼费</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp5_21">
        <el-checkbox v-model="query.ck_007_sys_setting_sp5_21">门店下单允许修改上楼费</el-checkbox>
      </el-form-item>
      <p class="title">服务费</p>
      <el-form-item prop="ck_007_sys_setting_sp5_22">
        <el-checkbox v-model="query.ck_007_sys_setting_sp5_22">话务下单允许修改服务费</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp5_23">
        <el-checkbox v-model="query.ck_007_sys_setting_sp5_23">门店下单允许修改服务费</el-checkbox>
      </el-form-item>

      <el-form-item prop="ck_007_sys_setting_1_24">
        <el-checkbox v-model="query.ck_007_sys_setting_1_24">押瓶租金按月收费，消单时按自然月自动计算租金</el-checkbox>
      </el-form-item>
      <!-- <el-form-item prop="ck_007_sys_setting_3_5">
        <el-checkbox v-model="query.ck_007_sys_setting_3_5">话务下单提交并继续派单</el-checkbox>
      </el-form-item> -->
      <el-form-item prop="ck_007_sys_setting_sp4_16">
        <el-checkbox v-model="query.ck_007_sys_setting_sp4_16">微信下单实名制</el-checkbox>
      </el-form-item>
      <!-- <el-form-item prop="ck_007_sys_setting_sp4_17">
        <el-checkbox v-model="query.ck_007_sys_setting_sp4_17">下单群发订单</el-checkbox>
      </el-form-item> -->
      <!-- <el-form-item prop="ck_007_sys_setting_sp4_20">
        <el-checkbox v-model="query.ck_007_sys_setting_sp4_20">订单备注自动带入安检单备注</el-checkbox>
      </el-form-item> -->
      <p class="title">押金均需回执</p>
      <div class="config-group">
        <el-form-item label="生效渠道：">
          <el-select v-model="query.depReceiptChannel" multiple placeholder="请选择" style="width: 25%;">
            <el-option
              v-for="item in channelOptions"
              :key="item.value"
              :label="item.desc"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </div>
      <el-form-item prop="ck_007_sys_setting_sp6_29">
        <el-checkbox v-model="query.ck_007_sys_setting_sp6_29">现金押金单回执时，需要用银行支付再次付款</el-checkbox>
      </el-form-item>
      <p class="title">
        <el-checkbox v-model="query.ck_007_sys_setting_sp6_25">
          订单未完成&nbsp;&nbsp;
          <el-input-number v-model="query.orderReturnDay" :min="1" :max="90" :controls="false" size="mini" style="width: 60px;" />
          天自动退单
        </el-checkbox>
      </p>
      <el-form-item prop="ck_007_sys_setting_sp6_30">
        <el-checkbox v-model="query.ck_007_sys_setting_sp6_30">回执已回的押金单退款时，只支持退现金</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp7_1">
        <el-checkbox v-model="query.ck_007_sys_setting_sp7_1">回执已回的订单退款时，只支持退现金</el-checkbox>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  export default {
    name: 'OrderTab',
    data() {
      return {
        query: {
          sp1: false,
          monthlyDayNum: '',
          buyMax: 999,
          exchangeBuyMax: 999,
          le: '',
          orderAppointCount: 2,
          ck_007_sys_setting_1_1: false,
          ck_007_sys_setting_1_2: false,
          ck_007_sys_setting_1_3: false,
          ck_007_sys_setting_2_28: false,
          ck_007_sys_setting_1_4: false,
          ck_007_sys_setting_1_9: false,
          ck_007_sys_setting_1_16: false,
          ck_007_sys_setting_1_11: false,
          ck_007_sys_setting_3_15: false,
          ck_007_sys_setting_sp4_9: false,
          ck_007_sys_setting_1_29: false,
          ck_007_sys_setting_2_27: false,
          ck_007_sys_setting_3_2: false,
          ck_007_sys_setting_1_6: false,
          ck_007_sys_setting_1_10: false,
          ck_007_sys_setting_1_17: false,
          ck_007_sys_setting_3_9: false,
          ck_007_sys_setting_1_27: false,
          ck_007_sys_setting_1_23: false,
          ck_007_sys_setting_1_24: false,
          ck_007_sys_setting_3_5: false,
          ck_007_sys_setting_sp4_16: false,
          ck_007_sys_setting_sp4_17: false,
          // ck_007_sys_setting_sp4_20: false
          ck_007_sys_setting_sp5_16: false,
          ck_007_sys_setting_sp5_17: false,
          ck_007_sys_setting_sp5_18: false,
          ck_007_sys_setting_sp5_19: false,
          ck_007_sys_setting_sp5_20: false,
          ck_007_sys_setting_sp5_21: false,
          ck_007_sys_setting_sp5_22: false,
          ck_007_sys_setting_sp5_23: false,
          ck_007_sys_setting_sp5_24: false,
          ck_007_sys_setting_sp5_25: false,
          ck_007_sys_setting_sp6_22: false,
          ck_007_sys_setting_sp6_25: false,
          ck_007_sys_setting_sp6_28: false,
          ck_007_sys_setting_sp6_29: false,
          ck_007_sys_setting_sp6_30: false,
          ck_007_sys_setting_sp7_1: false,
          depReceiptChannel: [],
          orderReturnDay: undefined
        },
        rules: {
          // le: [{ required: true, message: '请输入呼叫下单所属机构默认展开级数', trigger: 'change' }],
          // limitSpare: [{ required: true, message: '请输入微信下单未支付限时作废时间', trigger: 'change' }]
        },
        channelOptions: [
          {
            desc: '公众号/小程序',
            value: 1
          },
          {
            desc: '运气到家',
            value: 2
          },
          {
            desc: 'APP',
            value: 8
          },
          {
            desc: '企业端',
            value: 4
          }
        ]
      }
    },
    computed: {
      ...mapGetters([
        'corpSettingData', 'userInfo'
      ])
    },
    watch: {
      'query.ck_007_sys_setting_1_4': {
        async handler(newVal, oldVal) {
          if (newVal) {
            this.query.ck_007_sys_setting_1_9 = false
          }
        },
        deep: true,
        immediate: true
      },
      'query.ck_007_sys_setting_1_9': {
        async handler(newVal, oldVal) {
          if (newVal) {
            this.query.ck_007_sys_setting_1_4 = false
          }
        },
        deep: true,
        immediate: true
      },
      'query.ck_007_sys_setting_1_6': {
        async handler(newVal, oldVal) {
          if (newVal) {
            this.$bus.$emit('ck_007_sys_setting_1_6', false)
          }
        },
        deep: true,
        immediate: true
      }
    },
    async created() {
      this.init()
    },
    mounted() {
      this.$bus.$on('ck_007_sys_setting_1_7', (data) => {
        this.query.ck_007_sys_setting_1_6 = data
      })
    },
    methods: {
      init() {
        if (this.corpSettingData) {
          this.query.monthlyDayNum = this.corpSettingData.monthlyDayNum
          this.query.buyMax = this.corpSettingData.buyMax || ''
          this.query.exchangeBuyMax = this.corpSettingData.exchangeBuyMax || ''
          this.query.limitSpare = this.corpSettingData.limitSpare || ''
          this.query.ck_007_sys_setting_1_1 = !!(this.corpSettingData.sp1 >> 1 & 0x01)
          this.query.ck_007_sys_setting_1_2 = !!(this.corpSettingData.sp1 >> 2 & 0x01)
          this.query.ck_007_sys_setting_1_3 = !!(this.corpSettingData.sp1 >> 3 & 0x01)
          this.query.ck_007_sys_setting_1_4 = !!(this.corpSettingData.sp1 >> 4 & 0x01)
          this.query.ck_007_sys_setting_3_2 = !!(this.corpSettingData.sp3 >> 2 & 0x01)
          this.query.ck_007_sys_setting_1_6 = !!(this.corpSettingData.sp1 >> 6 & 0x01)
          this.query.ck_007_sys_setting_1_9 = !!(this.corpSettingData.sp1 >> 9 & 0x01)
          this.query.ck_007_sys_setting_1_10 = !!(this.corpSettingData.sp1 >> 10 & 0x01)
          this.query.ck_007_sys_setting_1_11 = !!(this.corpSettingData.sp1 >> 11 & 0x01)
          this.query['txt_007_sys_setting_1_12-14'] = !!((this.corpSettingData.sp1 >> 12 & 0x07) + 1)
          this.query.ck_007_sys_setting_1_16 = !!(this.corpSettingData.sp1 >> 16 & 0x01)
          this.query.ck_007_sys_setting_1_17 = !!(this.corpSettingData.sp1 >> 17 & 0x01)
          this.query['txt_007_sys_setting_1_18-21'] = !!(this.corpSettingData.sp1 >> 18 & 0xF)
          this.query.ck_007_sys_setting_1_23 = !!(this.corpSettingData.sp1 >> 23 & 0x01)
          this.query.ck_007_sys_setting_1_24 = !!(this.corpSettingData.sp1 >> 24 & 0x01)
          this.query.ck_007_sys_setting_1_27 = !!(this.corpSettingData.sp1 >> 27 & 0x01)
          this.query.ck_007_sys_setting_1_29 = !!(this.corpSettingData.sp1 >> 29 & 0x01)
          this.query.ck_007_sys_setting_2_2 = !!(this.corpSettingData.sp2 >> 2 & 0x01)
          this.query.ck_007_sys_setting_2_27 = !!(this.corpSettingData.sp2 >> 27 & 0x01)
          this.query.ck_007_sys_setting_3_5 = !!(this.corpSettingData.sp3 >> 5 & 0x01)
          this.query.ck_007_sys_setting_sp4_16 = !!(this.corpSettingData.sp4 >> 16 & 0x01)
          this.query.ck_007_sys_setting_sp4_17 = !!(this.corpSettingData.sp4 >> 17 & 0x01)
          // this.query.ck_007_sys_setting_sp4_20 = !!(this.corpSettingData.sp4 >> 20 & 0x01)
          this.query.ck_007_sys_setting_2_28 = !!(this.corpSettingData.sp2 >> 28 & 0x01)
          this.query.ck_007_sys_setting_3_15 = !!(this.corpSettingData.sp3 >> 15 & 0x01)
          this.query.ck_007_sys_setting_sp4_9 = !!(this.corpSettingData.sp4 >> 9 & 0x01)
          this.query.ck_007_sys_setting_3_9 = !!(this.corpSettingData.sp3 >> 9 & 0x01)

          this.query.ck_007_sys_setting_sp5_16 = !!(this.corpSettingData.sp5 >> 16 & 0x01)
          this.query.ck_007_sys_setting_sp5_17 = !!(this.corpSettingData.sp5 >> 17 & 0x01)
          this.query.ck_007_sys_setting_sp5_18 = !!(this.corpSettingData.sp5 >> 18 & 0x01)
          this.query.ck_007_sys_setting_sp5_19 = !!(this.corpSettingData.sp5 >> 19 & 0x01)
          this.query.ck_007_sys_setting_sp5_20 = !!(this.corpSettingData.sp5 >> 20 & 0x01)
          this.query.ck_007_sys_setting_sp5_21 = !!(this.corpSettingData.sp5 >> 21 & 0x01)
          this.query.ck_007_sys_setting_sp5_22 = !!(this.corpSettingData.sp5 >> 22 & 0x01)
          this.query.ck_007_sys_setting_sp5_23 = !!(this.corpSettingData.sp5 >> 23 & 0x01)
          this.query.ck_007_sys_setting_sp5_24 = !!(this.corpSettingData.sp5 >> 24 & 0x01)
          this.query.ck_007_sys_setting_sp5_25 = !!(this.corpSettingData.sp5 >> 25 & 0x01)
          this.query.ck_007_sys_setting_sp6_22 = !!(this.corpSettingData.sp6 >> 22 & 0x01)
          this.query.ck_007_sys_setting_sp6_25 = !!(this.corpSettingData.sp6 >> 25 & 0x01)
          this.query.ck_007_sys_setting_sp6_28 = !!(this.corpSettingData.sp6 >> 28 & 0x01)
          this.query.ck_007_sys_setting_sp6_29 = !!(this.corpSettingData.sp6 >> 29 & 0x01)
          this.query.ck_007_sys_setting_sp6_30 = !!(this.corpSettingData.sp6 >> 30 & 0x01)
          this.query.ck_007_sys_setting_sp7_1 = !!(this.corpSettingData.sp7 >> 1 & 0x01)
          this.query.orderReturnDay = this.corpSettingData.orderReturnDay || undefined
          if (this.corpSettingData.depReceiptChannel > 0) {
            this.channelOptions.forEach(channel => {
              const checked = ((this.corpSettingData.depReceiptChannel & channel.value) === channel.value)
              channel.checked = checked
            })
          }
          this.channelOptions.forEach(i => {
            if (i.checked) this.query.depReceiptChannel.push(i.value)
          })

          this.query.orderAppointCount = this.corpSettingData.orderAppointCount || 2
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
.form {
  .el-form-item {
    margin-bottom: 0;
  }
}

.title {
  margin: 10px 0 6px 0;
  font-size: 14px;
}
</style>
